package com.dede.getmusic.data

import org.json.JSONException
import org.json.JSONObject

/**
 * @author hsh
 * @date 2017/9/29 16:55.
 * @doc
 */
class BaseResult(json: String) {

    var result: String = ""
    var code: Int = 0
    var msg: String = ""
    var status: Boolean = false

    init {
        try {
            val obj = JSONObject(json)

            if (obj.has("body")) {
                this.code = obj.getInt("code")
            } else {
                this.code = obj.getInt("code")
                this.status = code == 200
            }

            if (obj.has("result"))
                this.result = obj.getString("result")

            if (obj.has("msg"))
                this.msg = obj.getString("msg")
        } catch (e: JSONException) {
            e.printStackTrace()
        }
    }
}
